package logic

import (
	"context"
	"novel-hub/novelrpc/novelrpc"

	"novel-hub/api/internal/svc"
	"novel-hub/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type NovelListApiLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewNovelListApiLogic(ctx context.Context, svcCtx *svc.ServiceContext) *NovelListApiLogic {
	return &NovelListApiLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *NovelListApiLogic) NovelListApi(req *types.NovelListRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	list, err := l.svcCtx.NovelRpc.NovelList(l.ctx, &novelrpc.NovelListRequest{
		Page:     req.Page,
		Size:     req.Size,
		Title:    req.Title,
		Category: req.Category,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "ok",
		Code:    200,
		Data:    list,
	}, nil
}
